package com.pearl.webflux.demo;

/**
 * @author TangDan
 * @version 1.0
 * @since 2023/4/12
 */

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/users")
public class MyRestController {

    @GetMapping("/{userId}")
    public Mono<User> getUser(@PathVariable Long userId) {
        User user = new User("zhangsan", "123456");
        return Mono.just(user);
    }

    @GetMapping("/{userId}/customers")
    public Flux<User> getUserCustomers(@PathVariable Long userId) {
        List<User> customers = new ArrayList<>();
        User user = new User("zhangsan", "123456");
        customers.add(user);
        return Flux.fromIterable(customers);
    }

    @DeleteMapping("/{userId}")
    public Mono<Void> deleteUser(@PathVariable Long userId) {
        System.out.println("删除用户：" + userId);
        return Mono.empty();
    }
}


